package com.guigu.basedservice.controller;


import com.github.pagehelper.PageInfo;
import com.guigu.basedservice.entity.BaseCarBrand;
import com.guigu.basedservice.entity.BaseCarType;
import com.guigu.basedservice.service.BaseCarBrandService;
import com.guigu.basedservice.utils.UniqueNumberGenerator;
import com.guigu.basedservice.vo.BaseCarBrandVo;
import com.guigu.commonutils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * <p>
 * 品牌(车辆) 前端控制器
 * </p>
 *
 * @author Heyuhang
 * @since 2024-09-11
 */
@CrossOrigin
@Api(description = "BaseCarBrand请求控制类")
@RestController
@RequestMapping("/basedservice/base-car-brand")
public class BaseCarBrandController {

    @Autowired
    private BaseCarBrandService baseCarBrandService;

    @Autowired
    private UniqueNumberGenerator uniqueNumberGenerator;

    @ApiOperation("查询所有BaseCarBrand分页数据")
    @RequestMapping("/show2/{currentPage}/{pageSize}")
    public R show2(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @RequestBody BaseCarBrandVo vo
            ){
        System.out.println("hao"+vo);
        PageInfo<BaseCarBrand> baseCarBrandPageInfo = baseCarBrandService.show2(vo,currentPage, pageSize);
        return R.ok().data("baseCarBrandPageInfo", baseCarBrandPageInfo);
    }

    @ApiOperation("查询所有selectType数据")
    @RequestMapping("/selectType")
    public R selectType() {
        BaseCarBrand baseCarBrand = baseCarBrandService.selectType();
        return R.ok().data("baseCarBrand", baseCarBrand);
    }

    @ApiOperation("查询所有BaseCarBrand数据")
    @GetMapping("/list")
    public R list() {
        List<BaseCarBrand> baseCarBrandList = baseCarBrandService.list(null);
        return R.ok().data("baseCarBrandList", baseCarBrandList);
    }

    @RequestMapping("/list2")
    public List<BaseCarBrand> list2(){
        return baseCarBrandService.list(null);
    }

    @RequestMapping("/getOne/{id}")
    public BaseCarBrand getOne(@PathVariable("id") String id){
        return baseCarBrandService.getById(id);
    }

    @ApiOperation("根据编号查询BaseCarBrand数据")
    @GetMapping("/{brandUuid}")
    public R byId(
            @ApiParam("查询主键id")
            @PathVariable("brandUuid") String brandUuid) {
        BaseCarBrand baseCarBrand = baseCarBrandService.getById(brandUuid);
        return R.ok().data("baseCarBrand", baseCarBrand);
    }

    @ApiOperation("根据id删除baseCarBrand数据")
    @RequestMapping("/delete/{brandUuid}")
    public R delete(@PathVariable String brandUuid){
        boolean flag = baseCarBrandService.removeById(brandUuid);
        return R.ok().data("flag", flag);
    }

    @ApiOperation("修改baseCarBrand数据")
    @RequestMapping("/update")
    public Boolean update(@RequestBody BaseCarBrand baseCarBrand){
        System.out.println("baseCarBrand++++"+baseCarBrand);
        return baseCarBrandService.updateById(baseCarBrand);
    }

    @ApiOperation("添加baseCarBrand数据")
    @PostMapping("/add2")
    public R add2(@RequestBody BaseCarBrand baseCarBrand){
        BaseCarBrand brand = baseCarBrandService.addBaseCarBrand(baseCarBrand);
        return R.ok().data("brand", brand).message("添加失败");
    }

    @ApiOperation("添加baseCarBrand数据")
    @RequestMapping("/addBaseCarBrand")
    public Boolean addBaseCarBrand(@RequestBody BaseCarBrand baseCarBrand){
        baseCarBrand.setBrandUuid(UniqueNumberGenerator.generateUniqueNumber());
        baseCarBrand.setVersion(BigDecimal.valueOf(0));
        baseCarBrand.setCreatedBy("aa");
        baseCarBrand.setCreatedDate(new Date());
        baseCarBrand.setUpdatedBy("bb");
        baseCarBrand.setUpdatedDate(new Date());
        return baseCarBrandService.save(baseCarBrand);
    }


}

